$( document ).ready(function() {

var actionsList={};
var actionsListIndex=0;
var vendor = {
		_add:"/user/add",
		_edit:"/user/edit",
		_delete:"/user/delete",
		_list:"/user/list",
		_get:"/user/get",
		_getAsJason:"/user/getJason"
		};

function _loadScreenFor(url){
	console.log(url);
	
	 $('#mainContentBody').fadeOut('slow');
	 $("#mainContentBody").load(url,function(){
			
			$('#mainContentBody').fadeIn('slow');
			 performFormatting();
		});
	 actionsList[actionsListIndex]=url;
	 $('._customeBox').remove();
	
	
 }

 function _doCommon(url){
		
	 /*$('#mainContentBody').hide('fast');
	 $("#mainContentBody").load(url);
	 $('#mainContentBody').show('fast');
	 actionsList[actionsListIndex]=url;*/
	 
	//alert(actionsList[actionsListIndex]+"/"+url);
	if("add"==url)
		$("#mainContentBody").load(actionsList[actionsListIndex]+"/"+url);
	
	performFormatting();
 }
 var _currDetailId='';
 function showObjectDetaisl(id, type)
 {
	 _currDetailId=type+id;
	
	 jQuery.ajaxSettings.traditional = true;
	
		var formData ={};
		formData["id"]=id;
		var params={url:"details",success:showBox,data:formData,type:"GET",dataType:"html"};
		doAjax(params);
 }
 
 //TODO:there is common logic of _loadScreenFor in this method. try to maintain them in generic way;
 function editObject(id, type)
 {
	 $('#mainContentBody').fadeOut('slow');
	
		var formData ={};
		formData[type+".Id"]=id;
		formData["id"]=id;
		$("#mainContentBody").load("edit",formData,function(){
			
			$('#mainContentBody').fadeIn('slow');
			performFormatting();
		});
		
 }
 function showBox(result)
 {
	 $('#'+_currDetailId).remove();
	 var _box= $( "#_boxContainer" ).clone();
	 $(_box).append(result)
	 	.attr('id',_currDetailId)
	 	.draggable({scroll: true })
	 	.addClass('_customeBox')
	  	.css('left',400)   
	 	.css('top',230)
	 	.find(".close").on('click',function(){$(_box).remove();});
	 $('body').append(_box);
	 $(_box).fadeIn('fast');
	 
 }
 
 function showError(result)
 {
	 $('#'+_currDetailId).remove();
	 var _box= $( "#_boxContainer" ).clone();
	 $(_box).append(result)
	 	.attr('id',_currDetailId)
	 	.draggable({scroll: true })
	 	.addClass('_customeBox')
	  	.css('left',400)   
	 	.css('top',230)
	 	.find(".close").on('click',function(){$(_box).remove();});
	 $('body').append(_box);
	 $(_box).fadeIn('fast');
	 
	 
 }
 
 function _loadContent(url,formObject)
 {
 	//$('.amount').inputmask('remove');
 		$("#breadcrumbs-one li a").removeClass('current');
 		$(this).addClass('current');
 		
 		jQuery.ajaxSettings.traditional = true;
 	
 		var formData = $("#"+formObject).serializeObject();
 		//formData.rateCards=assignedRate;
 		console.log("loading form with data----"+formData["financial.financialProductId"]);
 		var params={url:url,success:_showContent,data:formData,type:"POST",dataType:"html"};
 		doAjax(params);
 	
 } 

 
 function _showContent(result)
 {
 	
  	$('#window_content').empty();
  	$('#window_content').append(result);
  	$('#window_content').slideDown('slow');
  	
  	performFormatting();
	
 }
 
 function performFormatting()
 {
	 $(".number").inputmask("integer");
	  //$(".date").inputmask("dd/mm/yyyy");
	  $(".phone").inputmask("999-9999-999");
	  $(".amount").inputmask('decimal');
	  $(".decimal").inputmask('decimal');
	  $(".currency").inputmask('decimal');
	  //$(".alpha").inputmask('a',{repeat:30, defaults:{placeholder: ""}});
	  $(".date").datepicker();
	  $("select").chosen({width: "auto"});
	  
 }
});